/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openjawtech.xscraper.web.action;

import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import com.openjawtech.xscraper.web.service.AirportsService;
import com.openjawtech.xscraper.web.util.WebUtil;

/**
 *
 * @Created on 17-Mar-2009, 17:00:15
 * @author Wenbo.Sun
 */
public class GetAllArrivalsAction extends ActionSupport {
    private static final long serialVersionUID = 1L;
    private List<String> arrivals;
    private String departure;

    @Autowired
    private AirportsService airportsService;

    public List<String> getArrivals() {
        return arrivals;
    }

    public void setDeparture(String departure) {
        this.departure = departure;
    }

    @Override
    public String execute() throws Exception {
        Map<String, List> arrivalsMap = (Map<String, List>)WebUtil.getFromSession(WebUtil.ARRIVALS);
        if(arrivalsMap == null){
            arrivalsMap = new HashMap<String, List>();
            arrivalsMap.put(departure, airportsService.getAllArrivals(departure));
            WebUtil.addToSession(WebUtil.ARRIVALS, arrivalsMap);
        }
        else if(arrivalsMap.get(departure) == null)
            arrivalsMap.put(departure, airportsService.getAllArrivals(departure));
        arrivals = arrivalsMap.get(departure);
        return SUCCESS;
    }
}
